#pragma warning(disable:4996)

#include <stdio.h>
#include <string.h>
#include <limits.h>

static const int MAX_LEN = 150;
char board[8][MAX_LEN];

const char* bitmaps[10][8] = 
{
	{"  XXXX  ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	"  XXXX  ",
	},
	{"   XX   ",
	" XXXX   ",
	"   XX   ",
	"   XX   ",
	"   XX   ",
	"   XX   ",
	"   XX   ",
	" XXXXXX ",
	},
	{"  XXXX  ",
	" XX  XX ",
	" XX  XX ",
	"     XX ",
	"    XX  ",
	"   XX   ",
	"  XX    ",
	" XXXXXX ",
	},
	{"  XXXX  ",
	" X   XX ",
	"     XX ",
	"   XXX  ",
	"     XX ",
	"     XX ",
	" X   XX ",
	"  XXXX  ",
	},
	{"    XX  ",
	"   XXX  ",
	"   XXX  ",
	"  X XX  ",
	" X  XX  ",
	" XXXXXX ",
	"    XX  ",
	"  XXXXX ",
	},
	{"  XXXXX ",
	"  XX    ",
	"  XXXX  ",
	"  X  XX ",
	"     XX ",
	"     XX ",
	" X   XX ",
	"  XXXX  ",
	},
	{"   XXXX ",
	"  XX    ",
	" XX     ",
	" XXXXX  ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	"  XXXX  ",
	},
	{" XXXXXX ",
	" X   XX ",
	"     XX ",
	"    XX  ",
	"    XX  ",
	"    XX  ",
	"   XX   ",
	"   XX   ",
	},
	{"  XXXX  ",
	" XX  XX ",
	" XX  XX ",
	"  XXXX  ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	"  XXXX  ",
	},	
	{"  XXXX  ",
	" XX  XX ",
	" XX  XX ",
	" XX  XX ",
	"  XXXXX ",
	"     XX ",
	"    XX  ",
	" XXXX   ",
	},
};

int next(int offset)
{
	while (1)
	{
		for (int r = 0; r < 8; r++)
		{
			if (board[r][offset] == 'X')
				return offset;
			if (board[r][offset] == '\0')
				return -1;
		}
		offset++;
	}
}

bool isDigit(int n, int offset)
{
	for (int r = 0; r < 8; r++)
	{
		if (board[r][offset] != bitmaps[n][r][1])
			return false;
	}
	return true;
}

int getDigit(int offset)
{
	for (int n = 0; n < 10; n++)
	{
		if (isDigit(n, offset))
			return n;
	}
	return -1;
}

int main()
{
	int t;
	scanf("%d", &t);
	getchar();
	while (t--)
	{
		int len = INT_MAX;
		for (int r = 0; r < 8; r++)
		{
			gets(board[r]);
		}
		getchar();
		int a, b, offset;
		a = b = offset = 0;

		while (1)
		{
			offset = next(offset);
			int d = getDigit(offset);
			if (d == -1)
			{
				offset += 7; // +
				break;
			}
			else
			{
				a = a * 10 + d;
				offset += 6;
			}
		}

		while (1)
		{
			offset = next(offset);
			if (offset == -1)
				break;

			int d = getDigit(offset);
			b = b * 10 + d;
			offset += 6;
		}

		char sum[10];
		sprintf(sum, "%d", a + b);
		for (int i = 0; i < strlen(sum); i++)
		{
			int d = sum[i] - '0';
			for (int r = 0; r < 8; r++)
			{
				strcpy(&board[r][8*i], bitmaps[d][r]);
			}
		}
		for (int r = 0; r < 8; r++)
		{
			printf("%s\n", board[r]);
		}
		if (t)
			printf("\n");
	}

	return 0;
}